package com.senlingspace.web.controller.headquarters;

import java.util.List;

import com.senlingspace.system.domain.SlkjEquipment;
import com.senlingspace.system.domain.dto.EquipmentShopDto;
import com.senlingspace.system.domain.vo.SlkjEquipmentShopVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.senlingspace.common.annotation.Log;
import com.senlingspace.common.core.controller.BaseController;
import com.senlingspace.common.core.domain.AjaxResult;
import com.senlingspace.common.enums.BusinessType;
import com.senlingspace.system.domain.SlkjEquipmentShop;
import com.senlingspace.system.service.ISlkjEquipmentShopService;
import com.senlingspace.common.core.page.TableDataInfo;

/**
 * 门店设备Controller
 *
 * @author SenlingSpace
 * @date 2024-09-26
 */
@RestController
@RequestMapping("/system/equipmentShop")
public class SlkjEquipmentShopController extends BaseController {
    @Autowired
    private ISlkjEquipmentShopService slkjEquipmentShopService;

    /**
     * 查询门店设备列表
     */
    @PreAuthorize("@ss.hasPermi('system:equipmentShop:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentShopDto equipmentShopDto) {
        startPage();
        List<SlkjEquipmentShopVo> list = slkjEquipmentShopService.selectEquipmentShopList(equipmentShopDto);
        return getDataTable(list);
    }

    // /**
    //  * 导出门店设备列表
    //  */
    // @PreAuthorize("@ss.hasPermi('system:shop:export')")
    // @Log(title = "门店设备", businessType = BusinessType.EXPORT)
    // @PostMapping("/export")
    // public void export(HttpServletResponse response, SlkjEquipmentShop slkjEquipmentShop)
    // {
    //     List<SlkjEquipmentShop> list = slkjEquipmentShopService.selectSlkjEquipmentShopList(slkjEquipmentShop);
    //     ExcelUtil<SlkjEquipmentShop> util = new ExcelUtil<SlkjEquipmentShop>(SlkjEquipmentShop.class);
    //     util.exportExcel(response, list, "门店设备数据");
    // }

    /**
     * 获取门店设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:equipmentShop:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(slkjEquipmentShopService.selectSlkjEquipmentShopById(id));
    }

    /**
     * 新增门店设备
     */
    @PreAuthorize("@ss.hasPermi('system:equipmentShop:add')")
    @Log(title = "门店设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlkjEquipmentShop slkjEquipmentShop) {
        try {
            return toAjax(slkjEquipmentShopService.insertSlkjEquipmentShop(slkjEquipmentShop));
        } catch (IllegalArgumentException e) {
            return new AjaxResult(500, e.getMessage());
        }
    }

    /**
     * 修改门店设备
     */
    @PreAuthorize("@ss.hasPermi('system:equipmentShop:edit')")
    @Log(title = "门店设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlkjEquipmentShop slkjEquipmentShop) {
        return toAjax(slkjEquipmentShopService.updateSlkjEquipmentShop(slkjEquipmentShop));
    }

    // /**
    //  * 删除门店设备
    //  */
    // @PreAuthorize("@ss.hasPermi('system:shop:remove')")
    // @Log(title = "门店设备", businessType = BusinessType.DELETE)
    // @DeleteMapping("/{ids}")
    // public AjaxResult remove(@PathVariable Long[] ids)
    // {
    //     return toAjax(slkjEquipmentShopService.deleteSlkjEquipmentShopByIds(ids));
    // }

    @GetMapping("equipmentList")
    @PreAuthorize("@ss.hasPermi('system:equipmentShop:equipmentList')")
    public TableDataInfo equipmentList() {
        List<SlkjEquipment> slkjEquipments = slkjEquipmentShopService.selectSlkjEquipment();
        return getDataTable(slkjEquipments);
    }
}
